package com.sctvcloud.dongqu.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.base.BaseActivity;
import com.sctvcloud.dongqu.beans.HighRiseNewsInfo;
import com.sctvcloud.dongqu.beans.HighRiseTypeBean;
import com.sctvcloud.dongqu.beans.LiveItem;
import com.sctvcloud.dongqu.beans.NewsItem;
import com.sctvcloud.dongqu.beans.TopicItem;
import com.sctvcloud.dongqu.ui.activities.HighRiseMoreActivity;
import com.sctvcloud.dongqu.ui.activities.TopicDetailActivity;
import com.sctvcloud.dongqu.ui.util.IListShowData;
import com.sctvcloud.dongqu.ui.utils.GlideUtil;

import java.util.ArrayList;
import java.util.List;

public class HighRiseTypeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<HighRiseTypeBean> dataList ;
    private Context ctx;

    public HighRiseTypeAdapter(Context context, List<HighRiseTypeBean> list) {
        this.ctx = context;
        this.dataList = list;
    }

    static class TypeItemHolder extends RecyclerView.ViewHolder {
        CustomFontTextView typeName;
        View divider;

        public TypeItemHolder(View view) {
            super(view);
            divider = (View) view.findViewById(R.id.type_divider);
            typeName = (CustomFontTextView) view.findViewById(R.id.news_type_txt);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        if (null != dataList) {
            return dataList.size();
        }
        return 0;
    }

    public int setDataList(List<HighRiseTypeBean> list) {
        int pos = getItemCount();
        this.dataList = list;
        if (pos > 0) {
            notifyItemChanged(pos - 1);
        }
        return getItemCount() - 1;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder holder = null;
        View view = LayoutInflater.from(ctx).inflate(R.layout.item_high_rise_news_type, parent, false);
        holder = new TypeItemHolder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (null != dataList && dataList.size() > position) {
            final HighRiseTypeBean data = dataList.get(position);
            TypeItemHolder h = (TypeItemHolder) holder;
            if (position == 0) {
                h.divider.setVisibility(View.GONE);
            } else {
                h.divider.setVisibility(View.VISIBLE);
            }
            h.typeName.setText(data.getTypeName());
            h.typeName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    Intent intent = new Intent(ctx, TopicDetailActivity.class);
//                    intent.putExtra(BaseActivity.EX_URL, data.getTypeUrl());
                    Intent intent = new Intent(ctx, HighRiseMoreActivity.class);
                    intent.putExtra(HighRiseMoreActivity.HIGH_RISE_MORE, data.getTypeUrl());
                    ctx.startActivity(intent);
                }
            });

        }
    }

}

